package com.cskaoyan.controller;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.vo.WxFootprintListInnerVO;
import com.cskaoyan.service.WxFootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author zhuqiushi
 * @since 2022/09/09 10:48
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {
    @Autowired
    WxFootprintService wxFootprintService;
    /*
     * /wx/footprint/list?page=1&limit=10
     * GET
     * */
    @RequestMapping("list")
    public BaseRespVo<CommonData<WxFootprintListInnerVO>> list(Integer page, Integer limit) {
        //调用service层查询
        Session session = SecurityUtils.getSubject().getSession();
        MarketUser info = (MarketUser) session.getAttribute("info");
        Integer userId = 4;
        CommonData<WxFootprintListInnerVO> wxFootprintListInnerVOCommonData = wxFootprintService.list(page, limit,
                info.getId());
        BaseRespVo ok = BaseRespVo.ok(wxFootprintListInnerVOCommonData);
        return ok;
    }

    /*
     * /wx/footprint/delete
     * POST
     * */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map deleteMap) {
        //首先从中获取要删除的id
        Integer id = (Integer) deleteMap.get("id");
        //传入后端删除
        int code = wxFootprintService.delete(id);
        return BaseRespVo.ok();
    }

}
